const request = require("request");

// 填写 API Key
const apiKey = "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";

// API 地址
// const apiUrl = "https://api.openai.com/v1/engines/davinci/completions";
const apiUrl = "https://api.openai.com/v1/completions";

// 请求数据
const data = {
  model: "text-davinci-003",
  prompt: "什么是前端开发工程师？",
  temperature: 0.5,
  max_tokens: 20,
};

// 请求头
const headers = {
  "Content-Type": "application/json",
  Authorization: `Bearer ${apiKey}`,
};

// 发送请求
request.post(
  { url: apiUrl, headers: headers, json: data },
  (error, response, body) => {
    // console.log('response :>> ', response);
    if (error) {
      console.error(error);
    } else {
      // 输出响应
      console.dir(body, { depth: null });
    }
  }
);
